﻿<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="TemplateLabel.aspx.cs"
    Inherits="Whir_System_Module_Template_TemplateLabel" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>模板编辑</title>

    <script src="<%= Whir.Common.Settings.GetString("SystemPath") %>Whir_System/Js/JQuery/jquery.pack.js"
        type="text/javascript"></script>

    <script src="<%= Whir.Common.Settings.GetString("SystemPath") %>Whir_System/Js/JQuery/jquery.easydrag.js"
        type="text/javascript"></script>

    <script type="text/javascript">
	var txt;
	$(function(){
	    
	    txt = document.getElementById("txtHtml");
        
		$("#controlPanel").easydrag(false,["PanelHeader"]);
		$("#controlPanel").ondrop(function(){
				// save position info
				//notesData[id].x = parseInt($("#controlPanel").css("left"));
				//notesData[id].y = parseInt($("#controlPanel").css("top"));
		});
		
		$(window).scroll(function(){
		    if($("#btnDesign").val()=="代码"){
		        var y = document.body.scrollTop || this.scrollY;
		        if(undefined==y)y=0;
		        $("#controlPanel").winScroll(y);
		    }
		});


	});

    //解析呈现lable
    function tranLable(html)
    {
        var regLable = /<Whir:([a-zA-Z]+)[ ]+[^<>]*>[\s\S]*?<\/Whir:\1>/ig;
        var str = html.split(regLable);
        var lable = html.match(regLabe);
        var result = "";
        for(var k=0;k<str.length;k++)
        {
            result += str[k] + "<div>" + lable[k] + "</div>";
        }
        return result;
    }
	
	
	function getLable(labelId)
	{
	    var regAttr = /(?:[\w-:]+)(?:=(?:[^\s\>\<]*|\""[\s\S]*?\""|\'[\s\S]*?\'))?/ig;
	    var regName = /(?:[\w-:]+)/i;
	    var regArgument = /=(?:[\w-:]+|\"[\s\S]*?\"|\'[\s\S]*?\')/i;
	    var regLable = /<Whir:([a-zA-Z]+)[ ]+[^<>]*>[\s\S]*?<\/Whir:\1>/ig;
	    var str = txt.value.match(regLable);
	    var attr,name,val,strReslut;
	    for(var k=0;k<str.length;k++)
	    {
	        attr = str[k].match(regAttr);
	        for(var j=0;j<attr.length;j++)
	        {
	            name = attr[j].match(regName);
	            if(name[0].toLowerCase()=="id")
	            {
	                val = attr[j].match(regArgument);
	                var ss = val[0].substring(2,val[0].length-1);
	                if(labelId==ss)
	                {
	                    return str[k];
	                }
	            }
	        }
	    }
	    //return str;
	}
	
	function changeshowpanel(){   
        document.getElementById('divPanelContent').style.display = (document.getElementById('divPanelContent').style.display=="block") ? "none" : "block";  
        document.getElementById('PanelHeader').className = (document.getElementById('divPanelContent').style.display=="block")? "mynetToolBoxHeader_Div" : "mynetToolBoxHeader_Div2";
    }

    </script>

    <link href="<%= Whir.Common.Settings.GetString("SystemPath") %>Whir_System/Skin/Default/css/toolpanel.css"
        rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!-- 
    body {
        margin:0px;	   
	    padding: 0px;
    }
    
    td {
	    font: 12px "宋体";
    }
    
    Whir:UlList {
	    border: 1px solid #000000;
    }
    -->
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
            <tr>
                <td colspan="2" valign="top" class="form_tdText" bgcolor="#DADADA">
                    <div style="float: left">
                        <asp:Button ID="btnSubmit" runat="server" Text="保存" OnClick="btnSubmit_Click" />
                        <asp:Button ID="btnDesign" runat="server" OnClick="Button1_Click" Text="设计" /><!-- <input id="btnDesign" type="button" value="设计" onclick="view(this);" /> -->
                    </div>
                    <div style="float: right">
                        历史记录：<asp:DropDownList ID="ddlHistory" runat="server">
                        </asp:DropDownList><asp:Button ID="btnRestore" runat="server" Text="还原" OnClick="btnRestore_Click" />
                    </div>
                </td>
            </tr>
            <tr>
                <td valign="top">
                    <div id="controlPanel">
                        <div id="PanelHeader" class="mynetToolBoxHeader_Div" ondblclick="changeshowpanel();"
                            title="双击打开（关闭）工具箱">
                        </div>
                        <div class="mynetToolBox_Div" style="overflow-y: auto; height: 400px;" id="divPanelContent">
                            <table width="88%" border="0" cellpadding="0" cellspacing="1" bgcolor="#DADADA">
                                <tr>
                                    <td height="26" align="center" class="form_td"><font id="f1" onclick="show(1);" style="cursor: hand;
                                        color: Red;">内容</font>&nbsp;<font id="f2" onclick="show(2);" style="cursor: hand;">固定</font>&nbsp;<font
                                            id="f3" onclick="show(3);" style="cursor: hand;">定位</font> </td>
                                </tr>
                            </table>
                            <table id="tb1" width="88%" border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td height="30" align="center">
                                        <div class="labelDiv" onclick="setParam('UlList',650,410);" title="UL LI  样式的列表">
                                            UL LI列表标签</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="setParam('TableList',650,410);" title="表格样式的列表">
                                            Table列表标签</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="setParam('Page',500,230);">
                                            分页标签</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="window.open('SetFields.aspx', 'newwindow', 'height=480, width=150, top=46, left=158, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');"
                                            title="显示字段列表，方便复制字段标签">
                                            字段列表</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="setParam('Iframe',500,230);">
                                            嵌套标签</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="setParam('FormLabel',650,320);">
                                            表单标签</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="setParam('MenuLabel');">
                                            菜单标签</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="setParam('Slide',650,500);">
                                            幻灯片标签</div>
                                    </td>
                                </tr>
                            </table>
                            <table id="tb2" width="88%" border="0" cellpadding="0" cellspacing="0" style="display: none;">
                                <tr>
                                    <td height="30" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.SystemPath/}');">
                                            网站根路径</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.PicServer/}');">
                                            上传图片路径</div>
                                    </td>
                                </tr>
                                <tr style="display: none;">
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.ItemPicPath/}');">
                                            项目图片路径</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.SiteTitle/}');">
                                            网站标题 title</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.MetaKey/}');">
                                            网站关键字 keyword</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.MetaDesc/}');">
                                            网站描述 content</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.LogoUrl/}');">
                                            Logo 图</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.BannerUrl/}');">
                                            Banner 图</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.SiteICP/}');">
                                            站点 ICP</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.ICPUrl/}');">
                                            ICP 证书路径</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.Copyright/}');">
                                            版权</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.ADCatalog/}');">
                                            广告位</div>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="28" align="center">
                                        <div class="labelDiv" onclick="insertLabel('{Whir.Label.Email/}');">
                                            网站邮箱</div>
                                    </td>
                                </tr>
                            </table>
                            <table id="tb3" width="88%" border="0" cellpadding="0" cellspacing="0" style="display: none;">
                                <asp:Literal ID="Literal1" runat="server"></asp:Literal></table>
                        </div>
                        <div class="mynetToolBoxFooter_Div">
                        </div>
                    </div>
                </td>
                <td height="30" valign="top">
                    <asp:TextBox ID="txtHtml" runat="server" TextMode="MultiLine" Wrap="false" Width="100%"
                        Height="650px" CssClass="html" />
                </td>
            </tr>
        </table>
        <asp:Label ID="lblHtml" runat="server"></asp:Label>
        <!--<iframe id="lblHtml" frameborder="0" marginheight="0" marginwidth="0" width="1001" height="500" style="display:none" src="about:blank"></iframe>-->
    </form>
</body>
</html>

<script language="javascript">
<!--
function show(a)
{
    for(var i=1;i<=3;i++)
    {
        var f = document.getElementById("f"+i);
        var tb = document.getElementById("tb"+i);
        
        if(i==a)
        {
            tb.style.display = "";
            f.style.color = "red";
        }
        else
        {
            tb.style.display = "none";
            f.style.color = "black";
        }
    }
}

//插入固定标签
function insertLabel(str)
{
    var txt = document.getElementById("txtHtml");
    var temp = txt.value;

    txt.focus();
    document.selection.createRange().text = str;
    if(txt.value.indexOf(str) == 0)
    {
        txt.value = temp;
        alert("请选定待插入位置!");
    }
}

//插入内容标签
function setParam(name,width,height)
{
    var myArea = document.getElementById("txtHtml");
    var temp = myArea.value;
   
    myArea.focus();
    document.selection.createRange().text = "@_|_@";
    var MyArgs = myArea.value.split("@_|_@");    //分离
    
    if(myArea.value.indexOf("@_|_@") == 0)
    {
         myArea.value = temp;
         alert("请选定待插入位置!");
         return;
    }
    myArea.value = temp;    //还原
    
    //UlList,TableList,Page,FormLabel,MenuLabel,Slide,Iframe
    MyArgs = window.showModalDialog("<%=sysPath %>Whir_System/Module/Template/Set"+name+".aspx", MyArgs, "dialogHeight:"+height+"px; dialogWidth:"+width+"px;dialogFullscreen=no;");
    
    if(MyArgs != null)
        myArea.value = MyArgs[0] + MyArgs[1];
}  

//编辑内容标签
function editParam(name,id,width,height)
{
    var myArea = document.getElementById("txtHtml");
    
    var str = myArea.value.match(new RegExp("<Whir:"+name+"[ ]+ID=\""+id+"\"[^>]*>[^@|@]*?<\/Whir:"+name+">"));
    
    if(str!=null)
    {
        var Args = str[0];
        Args = window.showModalDialog("<%=sysPath %>Whir_System/Module/Template/Set"+name+".aspx?e", Args, "dialogHeight:"+height+"px; dialogWidth:"+width+"px;dialogFullscreen=no;");
        
        if(Args != null)
            myArea.value = myArea.value.replace(new RegExp("<Whir:"+name+"[ ]+ID=\""+id+"\"[^>]*>[^@|@]*?<\/Whir:"+name+">"), Args);
    }
}

//固定标签定位
function selectLabel(str, index)
{  
    var v = txt.value;
    var star=0;
    
    if(index > 0)
    {
        var v2=v;
        //改变前面相同的标签
        var str2=str.replace('{', '');
        for(var i=0; i<index; i++)
            v2 = v2.replace(str, str2);
            
        star = v2.search(new RegExp(str));
    }
    else
        star = v.search(new RegExp(str));
    
    if(star != -1)
    {
        //统计匹配前的换行数
        var vs = v.split('\n');
        var vlen = vs.length;
        var i;
        for(i=0; i<vlen; i++)
        {
            if(vs[i].indexOf(str) != -1)
                break;
        }
        //end
    
        var end = star - v.length + str.length;

        var rng = txt.createTextRange();
        rng.moveStart("character", star - i);
        rng.moveEnd("character", end + (vlen - i - 1));
        
        var first = rng.text.indexOf('{Whir.');
        if(first == 0)
            rng.select();
        else
        {
           if(rng.text.indexOf('\n{') != -1)
               first--;
           var rng2 = txt.createTextRange();
           //右移
           rng2.moveStart("character", star - i + first);
           rng2.moveEnd("character", end + (vlen - i - 1) + first);
           rng2.select();
        }
    }
} 

//内容标签定位
function selectLabel2(str)
{
    if(str.indexOf('{') == -1)
       str = "ID=\""+str+"\"";
    
    var v = txt.value;
    var star = v.search(new RegExp(str));
    
    if(star != -1)
    {
        //统计匹配前的换行数
        var vs = v.split('\n');
        var vlen = vs.length;
        var i;
        for(i=0; i<vlen; i++)
        {
            if(vs[i].indexOf(str) != -1)
                break;
        }
        //end
    
        var end = star - v.length + str.length;

        var rng = txt.createTextRange();
        rng.moveStart("character", star - i);
        rng.moveEnd("character", end + (vlen - i - 1));
        rng.select();
    }
}
//-->
</script>

